#include<bits/stdc++.h>
#include"BalanceTree.hpp"
using namespace std;

vector<int> data1,data2;

int main(){
    ios::sync_with_stdio(false);
    int n,x;
    cin>>n;
    for(int i=0;i<n;i++){
        cin>>x;
        data1.push_back(x);
        data2.push_back(x);
    }

    AVL_sort(data1);

    SP_sort(data2);
    
    for(long unsigned int i=0;i<data1.size();i++){
        if(data1[i]!=data2[i]){
            cout<<"Error!"<<endl;
            break;
        }
    }
    for(long unsigned int i=0;i<data1.size();i++) cout<<data1[i]<<' ';
    cout<<endl;
}